package com.zrwl.poscloud.xo.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.entity.CompanyAdminR;
import com.zrwl.poscloud.base.superI.SuperMapper;
import com.zrwl.poscloud.xo.vo.CompanyAdminRVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 商户管理员 Mapper类
 *
 * @author 刘思童 AutoGenerate
 * @date 2021-02-25
 */
public interface CompanyAdminRMapper extends SuperMapper<CompanyAdminR> {
    @Select("<script>" +
            " select" +
            "  r.uid,r.status,r.create_time createTime,r.update_time updateTime," +
            "  r.company_uid companyUid, r.admin_uid adminUid,r.company_code companyCode," +
            "  a.nick_name adminName, " +
            "  c.short_name companyName " +
            "   FROM t_company_admin_r r LEFT JOIN t_admin a ON r.admin_uid = a.uid " +
            "  LEFT JOIN t_company c ON r.company_uid = c.uid" +
            "<where>" +
            "   r.status =1" +
            "   <if test='param.adminUid!=null and param.adminUid!=&quot;&quot;'> " +
            "   and r.admin_uid = #{param.adminUid}" +
            "   </if>" +
            "   <if test='param.companyUid!=null and param.companyUid!=&quot;&quot;'>" +
            "    and r.company_uid = #{param.companyUid}" +
            "   </if>" +
            "</where>" +
            "</script>"
    )
    IPage<CompanyAdminRVO> getList(Page page, @Param("param") CompanyAdminRVO companyAdminRVO);

    @Select("<script>" +
            " select" +
            "  r.uid,r.status,r.create_time createTime,r.update_time updateTime," +
            "  r.company_uid companyUid, r.admin_uid adminUid,r.company_code companyCode," +
            "  a.nick_name adminName, " +
            "  a.mobile,  a.email, " +

            "  c.short_name companyName " +
            "   FROM t_company_admin_r r LEFT JOIN t_admin a ON r.admin_uid = a.uid " +
            "  LEFT JOIN t_company c ON r.company_uid = c.uid" +
            "<where>" +
            "   r.status =1" +
            "   <if test='param.adminUid!=null and param.adminUid!=&quot;&quot;'> " +
            "   and r.admin_uid = #{param.adminUid}" +
            "   </if>" +
            "   <if test='param.companyUid!=null and param.companyUid!=&quot;&quot;'>" +
            "    and r.company_uid = #{param.companyUid}" +
            "   </if>" +
            "</where>" +
            "</script>"
    )
    IPage<CompanyAdminRVO> getCompanyAdminList(Page page, @Param("param") CompanyAdminRVO companyAdminRVO);

    @Select("<script>" +
            " select" +
            "  r.status,r.update_time updateTime,r.company_code companyCode,a.nick_name createAdminNickName,c.short_name companyName" +
            "  FROM t_company_admin_r r LEFT JOIN t_admin a ON r.create_admin_uid = a.uid " +
            "  LEFT JOIN t_company c ON r.company_uid = c.uid" +
            "  where r.status =1 and a.status =1 and c.status =1 and r.admin_uid=#{adminUid}" +
            "</script>"
    )
    IPage<CompanyAdminRVO> getAdminCompanyList(Page page, @Param("adminUid") String adminUid);

    @Select("<script>" +
            "  SELECT b.uid adminUid, b.nick_name adminName " +
            "FROM t_admin b " +
            "where b.status != 0 and b.uid in(select admin_uid from t_company_admin_r where company_uid = #{param.companyUid} )" +
            "</script>"
    )
    IPage<CompanyAdminRVO> getPresentCompanyAdminList(Page page, @Param("param") CompanyAdminRVO companyAdminRVO);

    @Select("<script>" +
            " SELECT a.uid companyUid,a.full_name companyName,a.company_code companyCode FROM t_company a WHERE a.status=1 AND a.uid " +
            " NOT IN(SELECT b.company_uid FROM t_company_admin_r b WHERE b.status=1 AND b.admin_uid=#{param.adminUid}) " +
            "</script>"
    )
    List<CompanyAdminRVO> getPushAbleAdminInfoList(@Param("param") CompanyAdminRVO companyAdminRVO);
}
